# Maintainer: Konstantin Gizdov <arch at kge dot pw>
# Contributor: Baptiste Jonglez <baptiste--aur at jonglez dot org>

pkgname=ocaml-cairo
pkgver=0.6.4
pkgrel=1
pkgdesc="OCaml binding to Cairo, a 2D Vector Graphics Library"
arch=('loong64' 'x86_64')
url="https://github.com/Chris00/ocaml-cairo"
license=('LGPL3')
depends=('ocaml>=4.14.0' 'cairo' 'lablgtk2')
makedepends=('ocaml-findlib' 'dune')
source=("https://github.com/Chris00/ocaml-cairo/releases/download/${pkgver}/cairo2-${pkgver}.tbz")
sha256sums=('40357352d7205d3a5735855643830cb345f2db838ff9d19a532018760d468a05')

_dune_release_pkgs=('cairo2' 'cairo2-gtk' 'cairo2-pango')

dune_release_pkgs_comma() {
  # dune build needs a comma separated list of packages
  local dune_release_pkgs='dummy'
  for _pkg in "${_dune_release_pkgs[@]}"; do
    dune_release_pkgs+=",${_pkg}"
  done
  dune_release_pkgs="${dune_release_pkgs#dummy,}"
  echo "${dune_release_pkgs}"
}

build() {
  cd "${srcdir}/cairo2-${pkgver}"
  export OCAMLPATH="$(ocamlfind printconf destdir)"
  dune build -p "$(dune_release_pkgs_comma)"
}


package() {
  cd "${srcdir}/cairo2-${pkgver}"
  # we need to install packages one by one
  for _pkg in "${_dune_release_pkgs[@]}"; do
    dune install "${_pkg}" --destdir="${pkgdir}" --prefix="/usr" --libdir="$(ocamlfind printconf destdir)"
  done

  install -dm755 "${pkgdir}/usr/share/"
  mv "${pkgdir}/usr/doc" "${pkgdir}/usr/share/"
}
